#ifndef OBJECT2D_H
#define OBJECT2D_H

#include <vector>

namespace SGLEngine {

	class CObject2D : public CObject
	{
		//friend std::ostream& operator<< (std::ostream& o, const CObject2D& obj);
		protected:
			irr::core::vector2d<irr::s32>	pos;
			const std::string type;
		private:
			std::vector<irr::core::vector2di > start;
			std::vector<irr::core::vector2di > end;
			irr::core::vector2di highest;
			irr::core::vector2di lowest;
			std::vector<irr::video::SColor> color;
		public:
			friend class SGL;
			declareSGLfun(CObject2D()) : type("CObject2D"), pos(0,0), highest(0,0), lowest(0,0) {  }
			declareSGLfun(std::string getType()) { return this->type; }
			declareSGLfun(irr::f32 getX());
			declareSGLfun(irr::f32 getY());
			declareSGLfun(void addLine(irr::core::vector2di start, irr::core::vector2di end, irr::video::SColor col))
			{
				//Convert relative position to position2d
				if (highest == lowest)
				{
					if (start > end)
					{					
						highest = start;
						lowest = end;
					} else {
						highest = end;
						lowest = start;
					}
				} else {
					if (start > highest)
						highest = start;
					if (end > highest)
						highest = end;
					if (start < lowest)
						lowest = start;
					if (end < lowest)
						lowest = end;
				}
				this->start.push_back(start+pos);
				this->end.push_back(end+pos);
				this->color.push_back(col);
			}
			declareSGLfun(void Move(irr::s32 x, irr::s32 y))
			{
				irr::core::position2di mov(x, y);
				for(unsigned int i = 0; i < start.size(); i++)
				{
					start.at(i) += mov;
					end.at(i) += mov;
				}
			}
			declareSGLfun(void rotateBy(irr::f64 degrees, irr::core::vector2di center))
			{
				for(unsigned int i = 0; i < start.size(); i++)
				{
					start.at(i).rotateBy(degrees, center);
					end.at(i).rotateBy(degrees, center);
				}
			}
			declareSGLfun(irr::f32 center())
			{
				return (irr::f32)(highest.X + lowest.Y) / 2;
			}
			
	};

}

#endif